//
//  DetailModel.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/9/14.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class DetailModel: NSObject {
    var text:NSDictionary!//整个数据
    
    var avatar:String!//头像
    var userName:String!//用户名
    var price:String!//价格
    var title:String!//标题
    
    var bodyCount:Int!//数据的数量
    var bodyKey:Array<String> = []//数据的类型标志
    var bodyValue:Array<String> = []//数据
    
    init(text:NSDictionary) {
        super.init()
        self.text = text
        self.editJson()
    }
    
    //解析json
    func editJson(){
        self.avatar = text["avatar"] as! String
        self.userName = text["userName"] as! String
        self.price = text["price"] as! String
        self.title = text["title"] as! String
        
        //得到正文的数据
        let textBody = self.text["text"] as! NSArray
        let count = textBody.count
        self.bodyCount = count
        for i in 0..<count{
            let textDictionary = textBody[i] as! NSDictionary
            let textKey = textDictionary.allKeys[0] as! String
            let textValue = textDictionary[textKey] as! String
            self.bodyKey.insert(textKey, atIndex: i)
            self.bodyValue.insert(textValue, atIndex: i)
        }
    }
}








